import { Table,Pagination } from 'antd';
import React from 'react';
import TableTemplete from './TableTemplete';
class index extends React.Component {
    constructor(props) {
        super(props);
        this.state = { 
            columns:props.columns,
            rowKey:props.rowKey,
            refresh:props.refresh,
            dataSource:{},
            rowSelection:props.rowSelection||false,
            query:{page:0,pageSize:10,current:1},
            modal:{}
         };
    }
    componentWillMount(){
    }

    onRef=(ref)=>{
        this.setState({modal:ref})
    }
    
    onShowSizeChange=(current)=>{
        let {query,refresh}=this.state
        query.current=current
        this.setState({query,refresh:!refresh})
 
    }
    setTotal=(total)=>{
        this.setState({total})
    }
    render() {
        const {columns,rowKey,query,total} = this.state
        const {refresh}=this.props
        return (
            <div>
                {refresh&&<TableTemplete columns={columns} rowKey={rowKey} query={{...this.props.query,...query}} getData={this.props.getData} onRef={this.onRef} setTotal={this.setTotal}/>}
                {!refresh&&<TableTemplete columns={columns} rowKey={rowKey} query={{...this.props.query,...query}} getData={this.props.getData} onRef={this.onRef} setTotal={this.setTotal}/>}
                {total>0&&<Pagination 
                showTotal={(total)=>`共${total}条`}
                onChange={this.onShowSizeChange}
                defaultCurrent={1}
                pageSize={10}
                total={total}
                style={{float:'right',margin:20}}
                />}
            </div>
        );
    }
}

export default index;